<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>累加器</title>
</head>

<body>

</body>
<script>
    function iter() {
        var n = 0
        function add() {
            n++;
            return n
        }
        return add
    }

    var func = iter()
    var n = func()
    console.log(n);
    n = func()
    console.log(n);
    n = func()
    console.log(n);
    
</script>

</html>